package mysql

import "gorm.io/gorm"

type Goods struct {
	gorm.Model
	Title     string  `gorm:"type:varchar(20);not null;index:ip_idx commit:'房源标题'"`
	Cover     string  `gorm:"type:varchar(255);not null;index:ip_idx commit:'房源封面'"`
	Text      string  `gorm:"type:varchar(50);not null;index:ip_idx commit:'房源描述'"`
	Size      string  `gorm:"type:varchar(36);not null;index:ip_idx commit:'房源规格'"`
	Price     float64 `gorm:"type:decimal(10,2);not null;index:ip_idx commit:'房源价格'"`
	Evaluate  string  `gorm:"type:varchar(36);not null;index:ip_idx commit:'用户评价'"`
	LikeHouse int64   `gorm:"type:int;not null;index:ip_idx commit:'点赞数'"`
	Status    string  `gorm:"type:enum('已上架','未上架');not null;index:ip_idx commit:'房源状态'"`
	Stock     int64   `gorm:"type:int;not null;index:ip_idx commit:'房源库存'"`
}

func (g *Goods) List() (goods []*Goods, err error) {
	err = DB.Order("like_house desc").Find(&g).Error
	return
}
func (g *Goods) GoodsInfo(goodsID int64) (goods []*Goods, err error) {
	err = DB.Order("like_house desc").Where("id=?", goodsID).Find(&g).Error
	return
}
func (g *Goods) Create() error {
	return DB.Create(&g).Error
}
